<template>
  <div class="home-container">
    <!-- 顶部导航栏 -->
    <el-header class="header">
      <div class="header-title">后台管理系统</div>
      <div class="header-user">
        <el-dropdown>
          <span class="el-dropdown-link">
            <el-avatar :size="32" :src="userAvatar"></el-avatar>
            <span class="username">{{ username }}</span>
            <el-icon class="el-icon--right"><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人信息</el-dropdown-item>
              <el-dropdown-item>修改密码</el-dropdown-item>
              <el-dropdown-item divided @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
    
    <div class="main-container">
      <!-- 左侧菜单 -->
      <el-aside :width="isCollapse ? '64px' : '200px'" class="aside">
        <el-menu
          :default-active="activeMenu"
          class="el-menu-vertical"
          :collapse="isCollapse"
          router
        >
          <el-menu-item index="/placeholder" disabled style="pointer-events: none; opacity: 0; height: 0; overflow: hidden; height: 40px">
            <el-icon><Setting /></el-icon>
            <template #title></template>
          </el-menu-item>        
          <el-menu-item index="/home/management">
            <el-icon><Setting /></el-icon>
            <template #title>配置管理</template>
          </el-menu-item>
          <el-menu-item index="/home/file">
            <el-icon><Document /></el-icon>
            <template #title>文件管理</template>
          </el-menu-item>
        </el-menu>
        
        <div class="collapse-btn" @click="toggleCollapse">
          <el-icon v-if="isCollapse"><Expand /></el-icon>
          <el-icon v-else><Fold /></el-icon>
        </div>
      </el-aside>
      
      <!-- 右侧内容区 -->
      <el-main class="main">
        <router-view></router-view>
      </el-main>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ArrowDown, Document, Setting, Expand, Fold } from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

// 用户信息
const username = ref('Admin User')
const userAvatar = ref('https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png')

// 菜单相关
const isCollapse = ref(false)
const activeMenu = computed(() => route.path)

// 切换菜单折叠状态
const toggleCollapse = () => {
  isCollapse.value = !isCollapse.value
}

// 退出登录
const logout = () => {
  // 这里可以添加退出登录的逻辑，比如清除token等
  // localStorage.removeItem('token')
  router.push('/login')
}
</script>

<style scoped>
.home-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: #f8f9fa;
}

.header {
  background-color: #ffffff;
  color: #303133;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.header-title {
  font-size: 18px;
  font-weight: bold;
  color: #409EFF;
}

.header-user {
  display: flex;
  align-items: center;
}

.username {
  margin: 0 5px;
  color: #606266;
}

.el-dropdown-link {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #606266;
}

.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.aside {
  background-color: #ffffff;
  box-shadow: 0 2px 8px 0 rgba(29, 35, 41, 0.05);
  transition: width 0.3s;
  position: relative;
  overflow: hidden;
  border-right: 1px solid #f0f0f0;
}

.el-menu {
  border-right: none;
  height: 100%;
}

.el-menu-vertical:not(.el-menu--collapse) {
  width: 200px;
}

.main {
  background-color: #f8f9fa;
  overflow: auto;
  padding: 20px;
}

.collapse-btn {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #ffffff;
  color: #606266;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  border: 1px solid #f0f0f0;
}

/* 添加一些额外的样式美化 */
.el-menu-item.is-active {
  background-color: #ecf5ff !important;
  color: #409EFF !important;
  border-left: 3px solid #409EFF;
}

.el-menu-item:hover {
  background-color: #f5f7fa !important;
}


.el-menu-item.is-active .el-icon {
  color: #409EFF !important;
  display: inline-flex !important;
}

.el-menu-item .el-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.el-menu--collapse .el-menu-item .el-icon {
  display: inline-flex !important;
  margin-right: 0 !important;
}
</style>